home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws204.zip / WINDOWS.ZIP / DISPLAY.ASM next >
Assembly Source File  |  1991-07-15  |  32KB  |  599 lines

  1. ; DISPLAY.ASM ─ contains a collection of video-related procedures and
  2. ;               functions for use with Microsoft high-level languages.
  3. ;
  4. ;   Author:     Christy Gemmell
  5. ;   For:        Assembly-Language Toolbox for QuickBASIC
  6. ;   Version:    5.0
  7. ;   Date:       9/6/1991
  8. ;
  9. ;   Compatible with Microsoft QuickBASIC 4.x and BASIC 6 compilers.
  10. ;   Assembled using Microsoft Macro Assembler, MASM version 5.1
  11. ;
  12. ;┌────────────────────────────────────────────────────────────────────────┐
  13. ;│      Global symbols and procedures.                                    │
  14. ;└────────────────────────────────────────────────────────────────────────┘
  15. ;
  16.                 .model  medium
  17.  
  18.                 public  ScreenAddress
  19.                 public  ScreenCopy
  20.                 public  ScreenRead
  21.                 public  ScreenWrite
  22.                 public  VideoType
  23.                 public  WriteByte
  24.                 public  Attribute
  25.                 public  Delay
  26.                 public  Explode
  27.                 public  FastPrint
  28.  
  29.                 .code
  30.  
  31. ;┌────────────────────────────────────────────────────────────────────────┐
  32. ;│      Data Division.                                                    │
  33. ;└────────────────────────────────────────────────────────────────────────┘
  34. ;
  35. ;   Video parameters - default to monochrome screen display
  36. ;
  37. SnowFlag        db      0                       ; Snow prevention flag
  38. VideoRam        dw      0B000h                  ; Current video segment
  39. VideoPort       dw      03BAh                   ; Current video status port
  40. Param1          label   word
  41. Mode            db      7                       ; Current screen mode  
  42. Columns         db      80                      ; Current screen width
  43. Param2          label   word
  44. Rows            db      25                      ; Current screen length
  45. ActivePage      db      0                       ; Current video page
  46. TopLeft         label   word                    ; Upper left co-ordinates
  47. H1              db      ?                       ; Horizontal length
  48. V1              db      ?                       ; Vertical height
  49. BotRight        label   word                    ; Lower right co-ordinates
  50. H2              db      ?                       ; Horizontal length
  51. V2              db      ?                       ; Vertical height
  52.  
  53. Factor          label   word
  54.                 dw      0
  55.                 dw      0
  56. Counter         label   word
  57.                 dw      ?
  58.                 dw      ?
  59. Seed            label   word
  60.                 dw      7397
  61.                 dw      29447
  62.                 dw      802
  63. Multiple        label   word
  64.                 dw      179
  65.                 dw      183
  66.                 dw      182
  67. Modulus         label   word
  68.                 dw      32771
  69.                 dw      32779
  70.                 dw      32783
  71.  
  72. ;┌────────────────────────────────────────────────────────────────────────┐
  73. ;│      Calculate address from a pair of row/column co-ordinates.         │
  74. ;└────────────────────────────────────────────────────────────────────────┘
  75. ;
  76. ;   Given the row/column column co-ordinate of a character on the screen,
  77. ;   this function returns the segment:offset address of that character in
  78. ;   video memory. The address is correctly adjusted to the start of the
  79. ;   the currently active display page, but no check is made to ensure that
  80. ;   the co-ordinates supplied are within the actual screen bounds.
  81. ;
  82. ;   Input:      AL      = Row co-ordinate of character (base zero).
  83. ;               AH      = Column co-ordinate of character (base zero).
  84. ;
  85. ;   Output:     ES:DI==>  Address in video display buffer of the
  86. ;                         character cell specified.
  87. ;               DX      = CRT status register port address.
  88. ;
  89. ;   It is assumed that a previous call has been made to the VideoType
  90. ;   function, above, to determine the screen width, the port address of
  91. ;   the CRT status register and the correct video display segment.
  92. ;
  93. ScreenAddress   proc    far
  94.                 push    ax                      ; Save working registers
  95.                 push    bx
  96.                 mov     bh,ah                   ; Column to BH
  97.                 mov     bl,cs:Columns           ; Get current screen width
  98.                 shl     bl,1                    ; Add in attribute bytes
  99.                 mul     bl                      ; Multiply by row number
  100.                 xor     bl,bl                   ; Calculate
  101.                 xchg    bh,bl                   ;    column offset
  102.                 shl     bl,1                    ;      in BX
  103.                 add     ax,bx                   ; Add it to the row offset
  104.                 mov     di,ax                   ;    and copy to DI  
  105.                 xor     ax,ax                   ; Index to ROM-BIOS
  106.                 mov     es,ax                   ;    data in low memory
  107.                 mov     ax,es:[44Eh]            ; Get offset of current page
  108.                 add     di,ax                   ; Adjust target pointer
  109.                 mov     es,cs:VideoRam          ; Return segment of video RAM
  110.                 mov     dx,cs:VideoPort         ; Return CRT status port    
  111.                 pop     bx                      ; Clean up the stack
  112.                 pop     ax
  113.                 ret                             ;    and return to caller
  114. ScreenAddress   endp
  115.  
  116. ;┌────────────────────────────────────────────────────────────────────────┐
  117. ;│      Copy a character and attribute from the video display.            │
  118. ;└────────────────────────────────────────────────────────────────────────┘
  119. ;
  120. ;   If the 'snow prevention' flag is set, this routine waits until the
  121. ;   beginning of the next CRT horizontal retrace period before reading
  122. ;   data from the display. This is necessary only on machines fitted with
  123. ;   a Colour Graphics Adaptor (CGA) which may suffer from glitches or
  124. ;   screen snow if data is copied from the screen while the video buffer
  125. ;   is being refreshed.
  126. ;
  127. ;   Input:      DS:SI==>    Address of the screen location from which
  128. ;                           the data is to be copied. 
  129. ;               ES:DI==>    Address of the buffer into which the data
  130. ;                           is to be copied.
  131. ;               DX =        Port address of CRT status register.
  132. ;
  133. ;   Output:     SI and DI   Updated to point to next buffer locations.
  134. ;               AX          destroyed.
  135. ;
  136. ScreenCopy      proc    far  
  137.                 cmp     cs:SnowFlag,0           ; Snow prevention needed?
  138.                 cli                             ; Don't interrupt!
  139.                 jz      Copy_03                 ; No, don't bother
  140. Copy_01:
  141.                 in      al,dx                   ; Read video port
  142.                 test    al,1                    ; Test bit zero
  143.                 jnz     Copy_01                 ; Wait until it's reset
  144. Copy_02:
  145.                 in      al,dx                   ; Read port again
  146.                 test    al,1                    ; Test bit zero
  147.                 jz      Copy_02                 ; Wait until it's set
  148. Copy_03:
  149.                 movsw                           ; Transfer one word
  150.                 sti                             ; Restore interrupts
  151.                 ret
  152. ScreenCopy      endp
  153.  
  154. ;┌────────────────────────────────────────────────────────────────────────┐
  155. ;│      Read a character and attribute from the display.                  │
  156. ;└────────────────────────────────────────────────────────────────────────┘
  157. ;
  158. ;   This procedure is similar to ScreenCopy, above, except that the word
  159. ;   is simply loaded into AX instead of being copied into a buffer.
  160. ;
  161. ;   Input:      DS:SI==>    address, in the video display buffer, from
  162. ;                           where the data is to be read
  163. ;               DX =        port address of the CRT status register.
  164. ;
  165. ;   Output:     AL =        character at the specified address
  166. ;               AH =        display attribute given to character
  167. ;               DI          updated to point to the next word address
  168. ;
  169. ScreenRead      proc    far
  170.